// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: Wang Shuo wangshuo@sgsimulation.com
 * @Date: 2024-07-17 14:11:25
 * @LastEditors: wxc superjava@qq.com
 * @LastEditTime: 2024-09-29 12:49:44
 * @FilePath: /SGFEM/DBManager/src/Service/Coordinate/CORD2CService.cpp
 */
#include "DBManager/Service/Input/Coordinate/CORD2CService.h"

#include <cassert>

#include "DBManager/Common/ServiceMacro.h"
#include "DBManager/IRepository/Input/Coordinate/ICORD2CRepository.h"
#include "DBManager/Service/Input/Coordinate/CORDSummaryService.h"
using namespace SG::DBManager;

SERVICE_REG_WITH_DBM_IMPL (CORD2CService, ICORD2CRepository)

SERVICE_REG_CORD_SUMMARY (CORD2CService)
CORD2CService::CORD2CService (DBServiceFactory* const dbServiceFactory, ICORD2CRepository& repos)
    : CoordinateServiceBase<IRepos> (dbServiceFactory, repos)
{}

CORD2CService::~CORD2CService () = default;

std::vector<std::shared_ptr<SG::DataStructure::FEM::ICoordinate>> CORD2CService::GetAllCoord ()
{
    // 结果
    std::vector<std::shared_ptr<SG::DataStructure::FEM::ICoordinate>> allPtr;

    // 获取当前表内所有数据
    const auto datas = m_repository.GetAllData ();

    allPtr.reserve (datas.size ());

    // 遍历转换
    for (const auto& data : datas)
    {
        SG::Algebra::Point PA;
        PA.m_x = data.m_a1;
        PA.m_y = data.m_a2;
        PA.m_z = data.m_a3;

        SG::Algebra::Point PB;
        PB.m_x = data.m_b1;
        PB.m_y = data.m_b2;
        PB.m_z = data.m_b3;

        SG::Algebra::Point PC;
        PC.m_x = data.m_c1;
        PC.m_y = data.m_c2;
        PC.m_z = data.m_c3;

        allPtr.push_back (std::make_shared<SG::DataStructure::FEM::Cylinder2Coord> (data.m_id, data.m_rId, PA, PB, PC));
    }

    return allPtr;
}
